import { defineStore } from 'pinia'
import {nextTick} from "vue";
export const usePixiStore = defineStore('pixi', {
  // 为了完整类型推理，推荐使用箭头函数
  state: () => {
    return {
      _mouseControle:null,
      _screenResize:null,
      _pixiApp:null,

      pixiLoading:true,
      canvas2Dcontainer:[], // 存dom的 数组

      pixiMaxWidth:1690,
      pixiMaxHeight:806,

      // pixiMaxWidth:1248, // 画布的最大宽度  一般情况下与背景图片大小一致
      // pixiMaxHeight:797,  // 画布的最大高度  一般情况下与背景图片大小一致

      currentWidth:0,
      currentHeight:0,
      isRefresh:true,
    }
  },
  getters:{
  },
  actions:{
    changeCurrentWidth(){
      // console.log('document.documentElement.clientWidth',document.documentElement.clientWidth)
      this.currentWidth = parseInt(this.pixiMaxWidth/1920 * window.innerWidth)
    },
    changeCurrentHeight(){
      this.currentHeight = parseInt(this.pixiMaxHeight/1080 * window.innerHeight)
      // console.log('window.innerHeight',window.innerHeight,this.currentHeight)
    },
    changeMouseControle(val){
      this._mouseControle = val
    },
    changeScreenResize(val){
      this._screenResize = val
    },
    changePixiApp(value){
      this._pixiApp = value
    },
    changeCanvas2Dcontainer(value){
      this.canvas2Dcontainer.push(value)
    },
    clearCanvas2Dcontainer(){
      this.canvas2Dcontainer = []
    },
    changePixiLoading(value){
      this.pixiLoading = value
    },
    async changeIsRefresh(){
      this.isRresh = false;
      await nextTick()
      this.isRresh = true;
    }
  },
  persist:false
})


import { createPinia } from 'pinia';
const piniaInJs = createPinia();
export default piniaInJs;
